//*************************************************************************************
/** \file task_motor.h
 *    This file contains a task class for causing a motor to move a lever back and 
 *    forth. It's for a simple ME405 demonstration. When run, the task moves the two
 *    motors at rates controlled by readings from the A/D converters. 
 *
 *  Revisions:
 *    \li 02-06-2008 JRR Original file
 *    \li 01-18-2009 JRR Changed into more direct dual motor test program
 *    \li 01-19-2011 JRR Updated calls to newer version of stl_task constructor
 *
 *  License:
 *    This file released under the Lesser GNU Public License, version 2. This program
 *    is intended for educational use only, but it is not limited thereto. 
 */
//*************************************************************************************


//-------------------------------------------------------------------------------------
/** This class contains a task which moves a motorized lever back and forth. 
 *  WARNING:  This task uses an older version of parent class stl_task, and its 
 *            constructor parameters are out of date. Use it as an example, but
 *            do not attempt to just copy the parameters. 
 */

class task_motor : public stl_task
{
	protected:
		motor405* p_motor_1;				///< Pointer to one motor controller
		motor405* p_motor_2;				///< Pointer to another motor controller
		avr_adc* p_adc;						///< Pointer to A/D converter object

		bool going;							///< True if motor should be running now
		int angle_reading;					///< A/D reading from angle potentiometer
		bool direction;						///< True if we're going clockwise

	public:
		// The constructor creates a new task object
		task_motor (task_timer&, time_stamp&, motor405*, motor405*, avr_adc*);

		// The run method is where the task actually performs its function
		char run (char);

		// This method is called to tell the motor to go
		void go (void);
		
		// This method is called to tell the motor to stop moving
		void stop (void);

		// This method reverses the direction in which the motor moves
		void reverse (void) { direction = !direction; }
};
